<?php

/**
 * @author CuongNQ
 */

class SqlPartyTable{
   
  static function SqlSelectPartyById(){
      return "SELECT
                id
                ,name
                ,shortDesc
                ,desci
                ,createDate
                ,openDate
                ,closeDate
                ,address
                ,longitude
                ,latitude
                ,mostWant
                ,categoryID
                ,city
                ,openForSale
                ,adultParty
                ,partyCode
              FROM
                  parties
              WHERE
                  id = ?";
  }
  
  static function SqlParitesList($category = null,$mostWanted = null){
     $condition = array();
     $whereClause = '';
     if (!empty($category)) $condition[] = ' categoryID = ? ';
     if (!empty($mostWanted)) {
       $condition[] = ' mostWant = 1 ';
     }
     if (count($condition) > 0){
       $where = " WHERE " . implode(" AND ", $condition);
     }
     $sql = "SELECT
                name
                ,shortDesc
                ,desci
                ,createDate
                ,openDate
                ,closeDate
                ,address
                ,longitude
                ,latitude
                ,mostWant
                ,categoryID
                ,city
                ,openForSale
                ,adultParty
                ,partyCode
              FROM parties ";
     $sql .= $where;
     return $sql;
  }
  static function SqlGetUsersInParty($party_id){
    $where = '';
    if (!empty($party_id)) $where = ' WHERE up.partyID = ? ';
    $sql = "SELECT
                email
                ,facebookID
                ,fName
                ,lName
                ,cpf
                ,photo
                ,city
                ,lastLongtitude
                ,lastLattitude
                ,dob
                ,sex
                ,userPhoto
                ,allowAdult
                ,apiKey
              FROM user AS u
              INNER JOIN userinparty AS up ON u.id = up.userID ";
     $sql .= $where;
     return $sql;   
  }
  static function SqlGetNextParties(){
     $where = "WHERE openDate >= NOW() AND openDate <= DATE_ADD(NOW(),INTERVAL 2 DAY)";
     $sql = "SELECT
                  name
                  ,shortDesc
                  ,desci
                  ,createDate
                  ,openDate
                  ,closeDate
                  ,address
                  ,longitude
                  ,latitude
                  ,mostWant
                  ,categoryID
                  ,city
                  ,openForSale
                  ,adultParty
                  ,partyCode
              FROM parties ";
     $sql .= $where;
     return $sql;
  }
   static function SqlGetPromotionParties(){
     $where = "WHERE tc.promotion = 1 ";
     $sql = "SELECT
                  name
                  ,shortDesc
                  ,desci
                  ,createDate
                  ,openDate
                  ,closeDate
                  ,address
                  ,longitude
                  ,latitude
                  ,mostWant
                  ,categoryID
                  ,city
                  ,openForSale
                  ,adultParty
                  ,partyCode
              FROM parties AS p
              INNER JOIN ticketcat AS tc ON tc.partyID = p.id ";

     $sql .= $where;
     return $sql;
  }
  static function SqlValidateGenericCode(){
    $sql = "SELECT
                 partyCode
            FROM parties
            WHERE partyCode = ? ";
    return $sql;
  }
  static function SqlInsertTransfer(){
    $sql = "INSERT INTO transference(
              from,
              to,
              transferTime,
              ticketID
            )
            values(
              ?, ?, ?, ?
            )";
    return $sql;
  }
}